//
//  PackagesModel.swift
//  EmojiKeyBoard
//
//  Created by macs on 15/11/20.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

import UIKit

class PackagesModel: NSObject {
    //图片的模型数组
    var emoticons = [Emoji]()
    //分组的文件夹名称
    var id : String?
    //分组图片中文名
    var group_name_cn : String?
    
    init(id:String , name : String , emoticonArray : [[String : String]]) {
        super.init()
        self.id = id
        self.group_name_cn = name
        
        var index = 0
        for item in emoticonArray {
            
            let emoji = Emoji(id : id, dict: item)
            emoticons.append(emoji)
            index++
            if index == 20 {
                //添加删除数据的模型
                let em = Emoji(isRemove: true)
                emoticons.append(em)
                //开始新的一页
                index = 0
            }
        }
        //当不足21个时不足表情
        insertEmptyEmoji()
    }
    
    private func insertEmptyEmoji() {
        
        let count = emoticons.count % 21
        //正好21个
        if count == 0 {
            return
        }
        //当不够21个,补空,并且最后一个补删除
        for _ in count..<20 {
            
            let em = Emoji(isEmpty: true)
            emoticons.append(em)
        }
        let last = Emoji(isRemove: true)
        emoticons.append(last)
        
    }
    override var description : String {
        
        return "id = \(id!)--group_name_cn = \(group_name_cn!)"
    }
}
